<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>种养殖一体化智慧管理中心</title>
<meta
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="icon" href="/statics/favicon.ico" />
    <link rel="stylesheet"	href="${request.contextPath}/statics/css/bootstrap.min.css">
    <link rel="stylesheet"	href="${request.contextPath}/statics/css/font-awesome.min.css">
    <link rel="stylesheet"	href="${request.contextPath}/statics/css/AdminLTE.min.css">
    <link rel="stylesheet"	href="${request.contextPath}/statics/css/all-skins.min.css">
    <script src="${request.contextPath}/statics/libs/jquery.min.js"></script>
<script type="text/javascript"
	src="http://api.map.baidu.com/api?v=3.0&ak=r8aXwsks3aVHaFuQ0wxUEfwBLMCLuZH8"></script>
<style>
::-webkit-scrollbar-track {
	border-radius: 10px;
	-webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0);
}

::-webkit-scrollbar-thumb {
	background-color: rgba(0, 0, 0, 0.05);
	border-radius: 10px;
	-webkit-box-shadow: inset 1px 1px 0 rgba(0, 0, 0, .1);
}

::-webkit-scrollbar-thumb {
	background-color: rgba(0, 0, 0, 0.2);
	border-radius: 10px;
	-webkit-box-shadow: inset 1px 1px 0 rgba(0, 0, 0, .1);
}

::-webkit-scrollbar {
	width: 16px;
	height: 16px;
}

::-webkit-scrollbar-track, ::-webkit-scrollbar-thumb {
	border-radius: 999px;
	border: 5px solid transparent;
}

::-webkit-scrollbar-track {
	box-shadow: 1px 1px 5px rgba(0, 0, 0, .2) inset;
}

::-webkit-scrollbar-thumb {
	min-height: 20px;
	background-clip: content-box;
	box-shadow: 0 0 0 5px rgba(0, 0, 0, .2) inset;
}

::-webkit-scrollbar-corner {
	background: transparent;
}

html {
	overflow-x: hidden;
}
</style>
</head>
<body>
<div id="div_view_layer" style="display: none;">
    <div class="form-horizontal"></div>
</div>
	<section class="content">
		<div class="rows" style="margin-bottom: 1%; overflow: hidden;">
			<div style="float: left; width: 100%;">
				<div style="border: 1px solid #e6e6e6; background-color: #fff;">
					<div class="panel panel-default">
						<div class="panel-heading">
							<i class="fa fa-area-chart fa-lg" style="padding-right: 5px;"></i>
							<span class="info"></span>
						</div>
						<div class="panel-body" style="padding-bottom: 0px;">
							<div id="allmap" style="width: 100%;background:#0aaf19"></div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</section>
	<script type="text/javascript">

        function screenInfo(){
            if(window.innerHeight !== undefined){
                return {
                    "width": window.innerWidth,
                    "height": window.innerHeight
                }
            }else if(document.compatMode === "CSS1Compat"){
                return {
                    "width": document.documentElement.clientWidth,
                    "height": document.documentElement.clientHeight
                }
            }else{
                return {
                    "width": document.body.clientWidth,
                    "height": document.body.clientHeight
                }
            }
        }

		var map, opts, area1 = 0,area2 = 0,area3 = 0,area4 = 0, i;
		$(function() {
            var infos = screenInfo();
            $('#allmap').css({"height":(infos.height-60)+"px"},{"min-height":(infos.height-60)+"px"});
			map = new BMap.Map("allmap", {
				mapType : BMAP_HYBRID_MAP
			});
			map.centerAndZoom(new BMap.Point(106.6367, 26.6527), 9);
			map.addControl(new BMap.MapTypeControl({
				mapTypes : [ BMAP_NORMAL_MAP, BMAP_HYBRID_MAP ]
			}));
			map.setCurrentCity("贵阳"); // 设置地图显示的城市 此项是必须设置的
			map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
			opts = {
				width : 600,
				height : 600,
				title : "<span style='width:100%;text-align:center;color:#0aaf19;display:inline-block;font-weight:bold;'>基地信息</span><hr style=\"height:1px;color:#999;margin-top:10px;margin-bottom:0px;\" />",
				enableMessage : true
			};
            ajaxGetData('/farm/getAllFarm',{},function(data){
                if(data.code == 0){
                    data = data.data;
                    for (i = 0; i < data.length; i++) {
                        let icon = '';
                        var speciesId = data[i].speciesId;
                        switch (speciesId){
                            case 42:
                                icon = '/statics/images/zhongzhi.svg';
                                break;
                            case 43:
                                icon = '/statics/images/yangzhi.svg';
                                break;
                            case 44:
                                icon = '/statics/images/xumu.svg';
                                break;
                            case 45:
                                icon = '/statics/images/shuichan.svg';
                                break;
                            default:
                                break;
                        }
                        var marker = new BMap.Marker(new BMap.Point(data[i].longs,data[i].lat),{
                            icon : new BMap.Icon(icon,new BMap.Size(36,36))
                        }); // 创建标注
                        map.addOverlay(marker); // 将标注添加到地图中
                        addClickHandler(data[i].data_id,marker);
                        if(speciesId==42){//种植
                            area1 += parseInt(data[i].area);
                        }
                        if(speciesId==43){//养殖
                            area2 += parseInt(data[i].area);
                        }
                        if(speciesId==44){//畜牧
                            area3 += parseInt(data[i].area);
                        }
                        if(speciesId==45){//水产
                            area4 += parseInt(data[i].area);
                        }
                    }
                    $('.info').empty().append('全省基地总个数：' + i + '（个），其中种植面积为：' + area1 + '（亩），养殖数量为：' + area2 + '（头、羽、个、只），畜牧数量为：'+ area3 + '（头、个），水产数量为'+ area4 + '（吨）');
                }else{
                    $('.info').empty().append('全省基地总个数：' + 0 + '（个），其中种植面积为：' + 0 + '（亩），养殖数量为：' + 0 + '（头、羽、个、只），畜牧数量为：'+ 0 + '（头、个），水产数量为'+ 0 + '（吨）');
                }
            });
		});

		function addClickHandler(content, marker){
			marker.addEventListener("click", function(e){
				openInfo(content,e)
			});
		}

		function openInfo(dataId,e){
            ajaxGetData('/farm/info/'+dataId,{},function(data){
                if(data.code == 0){
                    data = data.data;
                    var html = '';
                    html += fitter('基地名称',data.name);
                    html += fitter('主体账号',data.user_name);
                    if(data.create_time != undefined){
                        html += fitter('创建时间',data.create_time);
                    }
                    if(data.type_name != undefined){
                        html += fitter('基地类型',data.type_name);
                    }
                    if(data.sales_name != undefined){
                        html += fitter('销售方式',data.sales_name);
                    }
                    if(data.longs != undefined){
                        html += fitter('基地纬度',data.longs);
                    }
                    if(data.lat != undefined){
                        html += fitter('基地纬度',data.lat);
                    }
                    if(data.city != undefined){
                        html += fitter('区域位置',(data.province_name != undefined ? data.province_name : "")+(data.city_name != undefined ? data.city_name : "")+(data.county_name != undefined ? data.county_name : "")+(data.villages_name != undefined ? data.villages_name : "")+(data.hamlet_name != undefined ? data.hamlet_name : ""));
                    }
                    if(data.address != undefined){
                        html += fitter('详细地址',data.address);
                    }
                    if(data.area != undefined){
                        html += fitter('基地面积',data.area+'亩');
                    }
                    if(data.species_name != undefined){
                        html += fitter('种养种类',data.species_name);
                    }
                    if(data.unit_name != undefined){
                        html += fitter('计量单位',data.unit_name);
                    }
                    if(data.link_man != undefined){
                        html += fitter('联系人',data.link_man);
                    }
                    if(data.link_tel != undefined){
                        html += fitter('联系电话',data.link_tel);
                    }
                    if(data.graphics != undefined && data.graphics.length > 0){
                        html += '<div class="col-sm-2 control-label">基地图片</div>';
                        html += '<div class="col-sm-10" style="border-bottom:1px solid #999;">';
                        html += "<div class=\"col-sm-12\" style='padding:6px 0'>";
                        var graphic = data.graphics.split(',');
                        for (var i = 0; i<graphic.length; i++){
                            var imageUrl = graphic[i];
                            if(imageUrl != undefined && imageUrl.length > 0){
                                html+='<a style="color:#459df5;margin-right:10px;" title="点击查看基地图片" target="_blank" href="../..'+imageUrl+'">基地图片'+(i+1)+'</a>';
                            }
                        }
                        html+="</div>";
                        html += '</div>';
                    }
                    if(data.status != undefined){
                        html += fitter('基地状态',data.status == 1 ? "正常" : "禁用");
                    }
                    $('#div_view_layer .form-horizontal').empty().html(html);
                    openInfoWindow(html,e);
                }else{
                    openInfoWindow(data.msg,e);
                }
            },'正在加载数据……');
		}

        function fitter(label,value){
            var html = '<div class="form-group">';
            html += '<div class="col-sm-2 control-label">'+label+'</div>';
            html += '<div class="col-sm-10" style="border-bottom:1px solid #999;">';
            html += '<div style="margin:6px 0;">'+value+'</div>';
            html += '</div>';
            html += '</div>';
            return html;
        }

		function openInfoWindow(html,e){
            var p = e.target;
            var point = new BMap.Point(p.getPosition().lng, p.getPosition().lat);
            var infoWindow = new BMap.InfoWindow(html, opts); // 创建信息窗口对象
            map.openInfoWindow(infoWindow, point); //开启信息窗口
        }

		function ajaxGetData(url,params,succeed,msg){
            var ajaxIndex;
		    if(msg != null && msg.length > 0){
                ajaxIndex  = top.layer.msg(msg,{icon:16,time:-1,shade:[0.3,'#000'],area:'auto'});
            }
            $.ajax({
                type : "GET",
                url : url,
                dataType : "json",
                data : params,
                success : function(data){
                    top.layer.close(ajaxIndex);
                    if(data.code == 205){
                        top.layer.alert('未登录或登录已超时',{
                            title : '系统提示',
                            area : ['300px','auto'],
                            btnAlign: 'c',
                            yes : function(index){
                                top.layer.close(index);
                                selfTopHref();
                            },
                            cancel : function(index,layero){
                                top.layer.close(index);
                                selfTopHref();
                            }
                        });
                    }else{
                        succeed(data);
                    }
                },
                error : function(response){
                    top.layer.close(ajaxIndex);
                    top.layer.alert('连接服务失败',{
                        title : '系统提示',
                        btnAlign: 'c',
                        yes : function(index){
                            top.layer.close(index);
                        }
                    });
                }
            });
        }

        window.selfTopHref = function(){
            if(self==top){
                window.location.href = '/logout';
            }else{
                top.location.href = '/logout';
            }
        };

		//获取物资信息
		function getGoodsInfo(dataId){}
	</script>
</body>
</html>